﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/Basic.Master" AutoEventWireup="true" CodeBehind="ContractList.aspx.cs" Inherits="PMS.UI.CM.ContractList" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            var height = $("#divTotal").height();
            var master = $("#master").height();
            var content = parseFloat(height) - parseFloat(master) - 30;
            $("#tbList").css("height", content);
        });
    </script>
    <script type="text/javascript">
        $(function () {
            $("#tbList").datagrid({
                url: '/Logic/CM/ContractAjax.aspx?method=GetContractList',
                loadMsg: '数据加载中请稍后……',
                fitColumns: false,
                pagination: true,
                queryParams: com.serializeSearchArray("form1"),
                rownumbers: true,
                idField: "ID",
                singleSelect: true,
                pageSize: 20,
                pageList: [20, 50, 100],
                striped: true,
                columns: [[{ field: 'ck', checkbox: true, width: 30 },
                 { field: 'ID', title: 'ID', align: "center", width: 40 },
                 {
                     field: 'Code', title: '合同编号 ', align: "center", width: 100
                 },

                   {
                       field: 'ContractName', title: '合同名称', align: "center", width: 100, editor: {
                           type: "validatebox",
                           options: {}
                       }
                   },
                 {
                     field: 'CustomerName', title: '需方', align: "center", width: 200
                 },

                 {
                     field: 'Address', title: '签订地点', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'SignDate', title: '签订时间', align: "center", width: 100, editor: {
                         type: "datebox",
                         options: {}
                     }
                 },

                 {
                     field: 'IsComplete', title: '是否完结', align: "center", width: 60,
                     formatter: function (value, row, Index) {
                         return com.getArrayText([{ value: "0", text: "未完结" }, { value: "1", text: "已完结" }], value);
                     }
                 },
                  {
                      field: 'CompleteDate', title: '完结日期', align: "center", width: 120
                  },
                 {
                     field: 'ContractMoney', title: '合同金额', align: "center", width: 60
                 },
                  {
                      field: 'InvoiceMoney', title: '开票金额', align: "center", width: 60,
                      formatter: function (value, row, Index) {
                          if (value == null || value == "") return 0;
                          else return value;
                      }
                  },
                 //{
                 //    field: 'IsInvoice', title: '是否开票', align: "center", width: 60,
                 //    formatter: function (value, row, Index) {
                 //        return com.getArrayText([{ value: "0", text: "未开票" }, { value: "1", text: "已开票" }], value);
                 //    }
                 //},
                 // {
                 //     field: 'InvoiceDate', title: '开票日期', align: "center", width: 100
                 // },
                   {
                       field: 'SupplierName', title: '供方', align: "center", width: 100
                   },
                 {
                     field: 'FillPerson', title: '制单人', align: "center", width: 100
                 },
                 {
                     field: 'FillDate', title: '制单日期', align: "center", width: 120
                 },
                {
                    field: 'Note', title: '备注', align: "center", width: 100, editor: {
                        type: "validatebox",
                        options: {}
                    }
                }]],
                onAfterEdit: function (rowIndex, rowData, changes) {
                    if (editAction == "edit") {
                        com.ajax({
                            url: "/Logic/CM/ContractAjax.aspx?method=EditContract",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    }
                    editRow = undefined;
                },
                onCancelEdit: function (rowIndex, rowData) {
                    $("#tbList").datagrid("rejectChanges");
                },
                onDblClickRow: function (rowIndex, rowData) {
                    top.wrapper.addTab("查看详细信息", "/UI/CM/ContractDetail.aspx?action=view&ID=" + rowData.ID)
                }
            });

        });

    </script>

    <script type="text/javascript">
        editRow = undefined;
        editAction = undefined;

        //编辑
        function funcEdit() {
            var row = $('#tbList').datagrid('getSelected');

            if (row) {
                if (row.IsComplete == '1') {
                    com.message("error", "该合同已完结，无法更改！");
                    return;
                }
                if (editRow != undefined) {
                }
                else {
                    var index = $("#tbList").datagrid('getRowIndex', row);
                    $("#tbList").datagrid('beginEdit', index);
                    editAction = "edit";
                    editRow = index;
                    rowData = $("#tbList").datagrid("getSelected");
                }
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        //查询
        function funcSearch() {
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
            editRow = undefined;
            editAction = undefined;
        }

        //删除
        function funcRemove() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                if (row.IsComplete == '1') {
                    com.message("error", "该合同已完结，无法删除！");
                    return;
                }
                $.messager.confirm('确认对话框', '您确定删除该合同吗？', function (r) {
                    if (r) {
                        com.ajax({
                            url: "/Logic/CM/ContractAjax.aspx?method=DelContract",
                            data: { ID: row.ID },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); $('#tbList').datagrid('clearSelections'); })
                            }
                        });

                    }
                });
            }
            else {
                com.message("information", "请选中一行");
            }
            editRow = undefined;
            editAction = undefined;
        }

        //取消编辑
        function funcCancel() {
            $('#tbList').datagrid("cancelEdit", editRow);
            editRow = undefined;
            editAction = undefined;
        }

        //重置
        function funcReload() {
            $("#form1").form("reset");
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
            editRow = undefined;
            editAction = undefined;
        }

        //保存
        function funcSave() {
            $('#tbList').datagrid('endEdit', editRow);
        }

        //完结合同
        function funcComplete() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                if (row.IsComplete == '1') {
                    com.message("information", "当前合同已完结");
                    return;
                }
                $.messager.confirm('确认对话框', '您确定完结该合同吗？', function (r) {
                    if (r) {
                        com.ajax({
                            url: "/Logic/CM/ContractAjax.aspx?method=DoneContract",
                            data: { ID: row.ID },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })
                            }
                        });
                    }
                })
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        //合同打印
        function funcPrint() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                top.wrapper.addTab("打印合同", "/UI/CM/PrintContract.aspx?Id=" + row.ID);
            }
            else {
                com.message("information", "请选中一行");
            }           
        }

    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="divTotal" style="height: 100%; width: 100%">

        <div id="master" class="container_16" style="height: auto">
            <form id="form1">
                <div class="grid_2 sealbl" style="">
                    合同编号 :
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="Code" name="Code" data-cp="co" />
                </div>
                <div class="grid_2 sealbl" style="text-align: right;">
                    需方 :
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" class="easyui-combobox" id="CustomerName" name="CustomerName" data-cp="=" data-options="valueField:'text',textField:'text',url:'/Logic/BD/CompanyAjax.aspx?method=GetAllCompanyNameList',panelHeight:'auto'" />
                </div>
                <div class="grid_2 sealbl" style="">
                    签订时间从:
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="startSignDate" name="startSignDate" data-cp="str>=" class="easyui-datebox" />
                </div>
                <div class="grid_2 sealbl">
                    到:
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" id="endSignDate" name="endSignDate" data-cp="str<=" class="easyui-datebox" />
                </div>
            </form>
        </div>
        <table id="tbList" title="合同信息表 " style="width: 100%">
        </table>
    </div>
</asp:Content>
